package voidlib;

/**
 * @author nevidimov
 */
public class VoidUtils {
   
    public static String toCamelCase(String s){
       String temp = s;
        if (s.startsWith("_")) {
           temp = s.substring(1);
       }
       String[] parts = temp.split("_");
       String camelCaseString = "";
       for (String part : parts){
          camelCaseString = camelCaseString + toProperCase(part);
       }
       return camelCaseString;
    }

    protected static String toProperCase(String s) {
        return s.substring(0, 1).toUpperCase() +
                   s.substring(1).toLowerCase();
    }
    
    public static String toUnderscore(String s) {
        StringBuilder b = new StringBuilder("");
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (Character.isUpperCase(ch)) {
                b.append("_");
                b.append(Character.toLowerCase(ch));
            } else {
                b.append(ch);
            }
        }
        return b.toString();
    }
}
